<template>
  <div>
    <navbar title="配送地址" :disabled="true"></navbar>
    <div style="position:relative;top:46px;">
      <div>
        <van-tabs v-model="active">
          <van-tab title="免费配送">
            <div style="margin:0.2rem;">
              <van-field
                v-model="frameNo"
                label="收件人姓名"
                type="textarea"
                placeholder="请输入姓名"
                rows="1"
                autosize
              />
              <van-field
                v-model="engineNo"
                label="手机号码"
                type="textarea"
                placeholder="请输入手机号码"
                rows="1"
                autosize
              />
              <van-cell is-link @click="showPop2">
                <template slot="title">
                  <span class="van-cell-text">投保地区</span>
                  <!-- <van-switch v-model="checked" size="20px" class="swich"/> -->
                  <span
                    class="van-cell-text"
                    style="position:absolute; left :105px; "
                  >{{firstRegisterDate}}</span>
                </template>
              </van-cell>
              <van-field
                v-model="engineNo"
                label="详细地址"
                type="textarea"
                placeholder="请输入详细地址"
                rows="3"
                autosize
              />
            </div>
          </van-tab>
          <van-tab title="上门自取">
            <div style="margin:0.2rem;background:#fff;text-align:center; padding:0.2rem;">
              <div>泰山保险 国泰民安</div>
              <div>客户服务电话：0531 55764142</div>
            </div>
          </van-tab>
        </van-tabs>
      </div>

      <div class="btnCon">
        <van-button size="large" type="default" @click="tihe">下一步</van-button>
      </div>
    </div>
  </div>
</template>

<script>
import navbar from "../components/navbar.vue";
import axios from "axios";
export default {
  components: { navbar },
  data() {
    return {
      active: 0,
      frameNo: "",
      engineNo: "",
      firstRegisterDate: "",
      baseInfo: window.localStorage.getItem("baseInfo")
    };
  },
  mounted() {
    this.baseInfo = JSON.parse(this.baseInfo);
    console.log(this.baseInfo);
  },
  methods: {
    //    ...
    showPop2() {},
    //  tihe(){
    //      console.log(1)
    //     this.$router.push({
    //         name: "updateVideo",
    //         query: {

    //         }
    //     });
    //  },
    tihe() {
      this.post(
        {
          memberCode: this.baseInfo.memberCode,
          orderId: this.baseInfo.orderId,
          ebusinessNo: this.baseInfo.ebusinessNo,
          phoneNumber: "",
          provinceCode: "",
          cityCode: "",
          provinceCName: "",
          orderAddress: "",
          receiveName: "",
          orderDay: "",
          countyCName: "",
          cityCName: "",
          countyCode: "",
          merchantName: "taishan",
          functionName: "SubmitAudit"
        },
        "api/services/app/car/SubmitAudit"
      ).then(res => {
        console.log(res.data.result.insuranceCode);
        var data = res.data.result;
        if (data.insuranceCode == 0) {
          if (data.udrMrk == "2") {
            var params = {
              ebusinessNo:  this.baseInfo.ebusinessNo,
              orderId:  this.baseInfo.orderId,
              merchantName: "taishan",
              functionName: "Payment"
            };
            this.post(params, "api/services/app/car/Payment").then(res => {
                console.log(res.data)
                if(res.data.success == true){
                    this.$dialog.confirm({
                    title: "提示",
                    message: "核保成功，点击确定支付订单",
                    confirmButtonText: "确定",
                    cancelButtonText: "返回",
                    closeOnClickOverlay: true
                    })
                    .then(() => {
                        window.location.href =  res.data.result.payurl
                    })
                    .catch(() => {
                    // on cancel
        
                    });
                 
                }
            });
          }else{
                //  Toast('已转人工核保，请等待');
            this.$dialog.alert({
            title: "提示",
            message:"已转人工核保，请等待",
            }).then(() => {
            // on confirm
                // this.$router.push({
                //     name: "listAddress",
                //     query: {
                    
                //     }
                // });
            })
          }
          //    console.log(res.data)
          //     if(res.data.data.submitCoreInfo.retCode == '1'){
          //         this.toToubao()
          //     }else if(res.data.data.submitCoreInfo.retCode == '0'){
          //         this.$dialog.confirm({
          //         title: '提示',
          //         message: res.data.data.submitCoreInfo.retMsg
          //         }).then(() => {
          //         // on confirm
          //             this.$router.push({
          //                 name: "updateVideo",
          //                 query: {

          //                 }
          //             });
          //         }).catch(() => {
          //         // on cancel
          //         });
          //     }
        } else {
          // console.log(data.insuranceMsg.match('传'))

          if (data.insuranceMsg.match("传") != null) {
            this.$dialog
              .confirm({
                title: "提示",
                message: data.insuranceMsg,
                confirmButtonText: "上传影像",
                cancelButtonText: "取消",
                closeOnClickOverlay: true
              })
              .then(() => {
                // on confirm
                this.$router.push({
                  name: "updateVideo",
                  query: {}
                });
              })
              .catch(() => {
                // on cancel
              });
          } else {
            this.$dialog
              .confirm({
                title: "提示",
                message: data.insuranceMsg,
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnClickOverlay: true
              })
              .then(() => {
                // on confirm
              })
              .catch(() => {
                // on cancel
              });
          }

          //   Toast('请求超时，请稍后再试');
        }
      });
    },
    toToubao: function() {
      this.$router.push({
        name: "underWriteSus",
        query: {}
      });
    }
  }
};
</script>
<style scoped lang="scss">
.con {
  padding: 10px 15px;
  background: #fff;
  .con_c {
    display: flex;
    div {
      width: 50%;
    }
  }
}
.btnCon {
  width: 10rem;
  position: fixed;
  bottom: 0;
  background: #fff;
}
</style>
